package com.zhai.test.algorithm.array;

/**
 * @Description: 二分查找 计算是否完全平方数
 * @ClassName: CacaulateSqureValue
 * @Author: zhaiyongxin
 * @Date: 2025/3/12 19:37
 * @Version: 1.0
 */
public class CalculateSqrtValue {
    public static void main(String[] args) {
        int x = 4;
        boolean i = void1(5);
        System.out.println(i);

    }

    /**
     *  x*x=mid return true
     *  x*x<mid left
     * @param x
     * @return
     */
    public static boolean void1(int x) {
        if (x == 0 || x == 1){
            return true;
        }
        boolean isSqrt = false;
        int left = 0;
        int right = x;
        while(left <= right) {
            int mid = left + (right - left) / 2;
            if (mid == (double)x/mid) {
                return true;
            } else if (mid < (double)x/mid) {
                left = mid + 1;
            } else {
                right = mid - 1;
            }
        }
        return isSqrt;
    }

}
